package com.crm.holidayConfig.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.crm.holidayConfig.domain.HolidayConfig;
import com.crm.holidayConfig.service.IHolidayConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节假日历Controller
 * 
 * @author ruoyi
 * @date 2024-01-29
 */
@RestController
@RequestMapping("/crmsys/holidayInfo")
public class HolidayConfigController extends BaseController
{
    @Autowired
    private IHolidayConfigService holidayConfigService;

    /**
     * 查询节假日历列表
     */
    @PreAuthorize("@ss.hasPermi('crmsys:holidayInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(HolidayConfig holidayConfig)
    {
        startPage();
        List<HolidayConfig> list = holidayConfigService.selectHolidayConfigList(holidayConfig);
        return getDataTable(list);
    }

    /**
     * 导出节假日历列表
     */
    @PreAuthorize("@ss.hasPermi('crmsys:holidayInfo:export')")
    @Log(title = "节假日历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HolidayConfig holidayConfig)
    {
        List<HolidayConfig> list = holidayConfigService.selectHolidayConfigList(holidayConfig);
        ExcelUtil<HolidayConfig> util = new ExcelUtil<HolidayConfig>(HolidayConfig.class);
        util.exportExcel(response, list, "节假日历数据");
    }

    /**
     * 获取节假日历详细信息
     */
    @PreAuthorize("@ss.hasPermi('crmsys:holidayInfo:query')")
    @GetMapping(value = "/{holiday}")
    public AjaxResult getInfo(@PathVariable("holiday") String holiday)
    {
        return success(holidayConfigService.selectHolidayConfigByHoliday(holiday));
    }

    /**
     * 新增节假日历
     */
    @PreAuthorize("@ss.hasPermi('crmsys:holidayInfo:add')")
    @Log(title = "节假日历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HolidayConfig holidayConfig)
    {
        return toAjax(holidayConfigService.insertHolidayConfig(holidayConfig));
    }

    /**
     * 修改节假日历
     */
    @PreAuthorize("@ss.hasPermi('crmsys:holidayInfo:edit')")
    @Log(title = "节假日历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HolidayConfig holidayConfig)
    {
        return toAjax(holidayConfigService.updateHolidayConfig(holidayConfig));
    }

    /**
     * 删除节假日历
     */
    @PreAuthorize("@ss.hasPermi('crmsys:holidayInfo:remove')")
    @Log(title = "节假日历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{holidays}")
    public AjaxResult remove(@PathVariable String[] holidays)
    {
        return toAjax(holidayConfigService.deleteHolidayConfigByHolidays(holidays));
    }
}
